<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\WxShopAddress;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class WxShopAddressController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new WxShopAddress(['user']), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('user.user_avatar','头像')->image('',30,30);
            $grid->column('user.user_name','用户');
            $grid->column('name');
            $grid->column('mobile');
            $grid->column('province');
            $grid->column('city');
            $grid->column('county');
            $grid->column('adds');
//            $grid->column('user_id');
            $grid->column('is_check')->using([0=>'否',1=>'是'])->label([
                0=>'green',
                1=>'red'
            ]);
            $grid->column('state')->using([0 => '正常', 1 => '用户删除'])->label([
                0 => 'blue',
                1 => 'primary',
            ]);
            $grid->column('created_at');
//            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new WxShopAddress(), function (Show $show) {
            $show->field('id');
            $show->field('name');
            $show->field('mobile');
            $show->field('province');
            $show->field('city');
            $show->field('county');
            $show->field('adds');
            $show->field('user_id');
            $show->field('is_check');
            $show->field('state');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new WxShopAddress(), function (Form $form) {
            $form->display('id');
            $form->text('name');
            $form->text('mobile');
            $form->text('province');
            $form->text('city');
            $form->text('county');
            $form->text('adds');
            $form->text('user_id');
            $form->text('is_check');
            $form->text('state');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
